/**
 * semver lite
 */

function Semver() {

}

Object.assign(Semver, {
    clean(version) {
        return version.trim().replace(/^[^\d]+/, '');
    },
    toStr(versionNum) {
        const major = parseInt((versionNum / 1e8) > 1 ? versionNum / 1e8 : 0);
        const minor = parseInt(((versionNum - (major * 1e8)) / 1e5) > 1 ? (versionNum - (major * 1e8)) / 1e5 : 0);
        const patch = parseInt((versionNum - (major * 1e8) - (minor * 1e5)));
        return [major, minor, patch].join('.');
    },
    toInt(version) {
        version = this.clean(version);

        const m = version.split('.');
        const major = 1e8 * (+m[0] || 0);
        const minor = 1e5 * (+m[1] || 0);
        const patch = +m[2] || 0;

        return major + minor + patch;
    },

    gt(a, b) {
        return this.toInt(a) > this.toInt(b);
    },
    gte(a, b) {
        return this.toInt(a) >= this.toInt(b);
    },
    lt(a, b) {
        return this.toInt(a) < this.toInt(b);
    },
    lte(a, b) {
        return this.toInt(a) <= this.toInt(b);
    }
});

module.exports = Semver;